package ooday04;


public class Test {
    public static void main(String[] args) {
        Animal[] animals = new Animal[5];
        animals[0] = new Dog("小黑子",2,"黑");
        animals[1] = new Dog("小白子",3,"白");
        animals[2] = new Chick("坤坤",2,"黑");
        animals[3] = new Chick("只因",3,"鸡");
        animals[4] = new Fish("茵茵",4,"金");
        for (int i=0;i<animals.length;i++){
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();

            if (animals[i] instanceof Dog){
                Dog dog = (Dog) animals[i];
                dog.lookHome();
            }

            if (animals[i] instanceof Chick){
                Chick chick = (Chick) animals[i];
                chick.layEggs();
            }

            if (animals[i] instanceof Fish){
                Fish fish = (Fish) animals[i];
                fish.swim();
            }
        }

        /*
        Master master = new Master();
        Dog dog = new Dog("小黑",4,"黑");
        Fish fish = new Fish("桐桐",6,"红");
        Chick chick = new Chick("鸡鸡",4,"绿");
        master.feed(dog); //在传参的同时，系统自动做了向上造型
        master.feed(fish);
        master.feed(fish);
         */

    }
}
